package com.thinking.in.spring.ioc.dependency.source;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.PropertySource;

/**
 *
 * 外部化配置作为依赖来源 示例
 *
 *      必须要加 Configuration注解才可以
 * @author : zjj
 * @date : 2022/1/26 9:50
 */
@PropertySource("META-INF/default.properties")
@Configuration
public class ExternalConfigurationDependencySourceDemo {

    @Value("${user.id}")
    private Long id;


    @Value("${user.source}")
    private String source;


    public static void main(String[] args) {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(ExternalConfigurationDependencySourceDemo.class);

        applicationContext.refresh();


        System.out.println(applicationContext.getBean(ExternalConfigurationDependencySourceDemo.class).id);
        System.out.println(applicationContext.getBean(ExternalConfigurationDependencySourceDemo.class).source);

        applicationContext.close();
    }
}
